package pers.cj.pdos.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.cj.pdos.entity.CustomType;
import pers.cj.pdos.entity.ProviderType;
import pers.cj.pdos.mapper.ProviderTypeMapper;
import pers.cj.pdos.service.IProviderTypeService;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenj
 * @since 2019-12-12
 */
@Service
public class ProviderTypeServiceImpl extends ServiceImpl<ProviderTypeMapper, ProviderType> implements IProviderTypeService {
    @Autowired
    private ProviderTypeMapper providerTypeMapper;
    @Override
    public long count(String companyId) {
        return providerTypeMapper.selectCount(new QueryWrapper<ProviderType>().eq("company_id",companyId));
    }

    @Override
    public List<ProviderType> listPage(Integer page, Integer limit, String companyId) {
        QueryWrapper<ProviderType> wrapper = new QueryWrapper<>();
        wrapper.eq("company_id",companyId);

        if (page !=null && limit != null) {
            IPage<ProviderType> iPage = providerTypeMapper.selectPage(new Page<>(page,limit), wrapper);
            return iPage.getRecords();
        } else {
            return providerTypeMapper.selectList(wrapper);
        }
    }

    @Override
    public boolean checkName(String name, String companyId) {
        return providerTypeMapper.selectCount(new QueryWrapper<ProviderType>().eq("name",name).eq("company_id",companyId)) > 0;
    }
}
